package slave.sspGUI;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;

import javax.swing.ImageIcon;
import javax.swing.WindowConstants;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JProgressBar;

import slave.SlaveStreamProvider;


/**
 * This code was edited or generated using CloudGarden's Jigloo
 * SWT/Swing GUI Builder, which is free for non-commercial
 * use. If Jigloo is being used commercially (ie, by a corporation,
 * company or business for any purpose whatever) then you
 * should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details.
 * Use of Jigloo implies acceptance of these licensing terms.
 * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
 * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
 * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
@SuppressWarnings("serial")
public class ClientJPanel extends javax.swing.JPanel {
	private String c_mac;	
	private String c_port;	
	private String c_stack;	
	private String c_streamBar;	
	@SuppressWarnings("unused")
	private String c_kbps;	
	private String c_file;	
	private SlaveStreamProvider ssp;


	public ClientJPanel(SlaveStreamProvider ssp,String mac, String port, String stack,String streamBar, String kbps, String file) {
		super();
		this.ssp=ssp;
		this.c_mac = mac;
		this.c_port = port;
		this.c_stack = stack;
		this.c_streamBar = streamBar;
		this.c_kbps = kbps;
		this.c_file = file;
		initGUI();
	}

	public ClientJPanel() {
		super();
		initGUI();
	}


	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}



	private JLabel mac = new JLabel();
	public JLabel getMac() {
		return mac;
	}

	public void setMac(JLabel mac) {
		this.mac = mac;
		mac.setPreferredSize(new java.awt.Dimension(163, 12));
	}

	private JProgressBar StreamBar = new JProgressBar();
	public JProgressBar getStreamBar() {
		return StreamBar;
	}

	public void setStreamBar(JProgressBar streamBar) {
		StreamBar = streamBar;
	}

	private JButton stop = new JButton();
	public JButton getStop() {
		return stop;
	}

	public void setStop(JButton stop) {
		this.stop = stop;
		stop.setPreferredSize(new java.awt.Dimension(62, 23));
	}

	private JLabel icon = new JLabel();
	public JLabel getIcon() {
		return icon;
	}

	public void setIcon(JLabel icon) {
		this.icon = icon;
	}

	private JLabel port = new JLabel();
	private JLabel stack = new JLabel();
   	public JLabel getStack() {
		return stack;
	}

	private JLabel kb;

	public JLabel getPort() {
		return port;
	}

	public void setPort(JLabel port) {
		this.port = port;
	}

	private JLabel file = new JLabel();
	public JLabel getFile() {
		return file;
	}

	private JLabel velocity = new JLabel();

	public JLabel getVelocity() {
		return velocity;
	}

	public void setVelocity(JLabel velocity) {
		this.velocity = velocity;
		velocity.setPreferredSize(new java.awt.Dimension(42, 13));
		velocity.setText("00.000");
	}

	/**
	 * Auto-generated main method to display this 
	 * JPanel inside a new JFrame.
	 */
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new ClientJPanel());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}


	private void initGUI() {
		try {
			ImageIcon user = new ImageIcon("./media/user.png");
			setPreferredSize(new Dimension(300,130));
			AnchorLayout thisLayout = new AnchorLayout();
			this.setLayout(thisLayout);
			{
				kb = new JLabel();
				this.add(kb, new AnchorConstraint(488, 1015, 626, 868, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				kb.setText("KB/s");
				kb.setPreferredSize(new java.awt.Dimension(44, 18));
			}
			{
				this.add(icon, new AnchorConstraint(150, 205, 796, 1, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				icon.setIcon(user);
				icon.setPreferredSize(new java.awt.Dimension(61, 84));
			}
	
			{
				this.add(stop, new AnchorConstraint(157, 961, 334, 755, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				stop.setText("stop");
				ActionListener listener = new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						try{
							ssp.closeClient(c_mac,"STOPPED");
							System.out.println("clientJpanel: chiudo "+c_mac);
						}catch(Exception ex){
							ex.printStackTrace();	
						}
					}	

				};
				stop.addActionListener(listener );
			}
			{
				this.add(velocity, new AnchorConstraint(519, 861, 619, 735, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				velocity.setFont(new java.awt.Font("AlArabiya",0,12));
			}
			{
				this.add(StreamBar, new AnchorConstraint(342, 961, 488, 208, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				StreamBar.setStringPainted(true);
				StreamBar.setMaximum(Integer.parseInt(c_streamBar));
				StreamBar.setPreferredSize(new java.awt.Dimension(226, 19));
			}
			{
				this.add(mac, new AnchorConstraint(226, 755, 319, 211, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				mac.setText("MAC: "+c_mac);
				mac.setFont(new java.awt.Font("AlArabiya",0,12));
			}
			{
				this.add(port, new AnchorConstraint(480, 628, 642, 211, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				port.setText("Bluetooh port: "+c_port);
				port.setFont(new java.awt.Font("AlArabiya",0,12));
				port.setPreferredSize(new java.awt.Dimension(125, 21));

			}
			
			{
			
				this.add(stack, new AnchorConstraint(611, 755, 757, 211, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				stack.setText("Stack bluetooth used/"+c_stack);
				stack.setFont(new java.awt.Font("AlArabiya",0,12));
				stack.setPreferredSize(new java.awt.Dimension(163, 15));
			}
			
			{
				this.add(file, new AnchorConstraint(750, 755, 865, 211, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				file.setText("File name: "+c_file);
				file.setFont(new java.awt.Font("AlArabiya",0,12));
				file.setPreferredSize(new java.awt.Dimension(163, 20));
			}
			
			
			
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
